<?php
require_once ('../lib/config.php');
require_once ('../lib/facebook.php');
require_once ('../lib/friends.php');
require_once ('../lib/friend.php');
require_once ('../lib/init.php');
$me = getOneself();

if(!$me){
    print $login_button;
    exit();
}else{
    print $logout_button;
}

/*
 * TEST CODE START
 */
try{
    
//    $query = "SELECT status_id, message, source FROM status WHERE uid = 100000526102422";
//    $query = "SELECT status_id, message, source FROM status WHERE uid = me()";
//    $query = "SELECT uid, name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())";

//    $query = "SELECT source_id, target_id, target_type FROM connection WHERE source_id = me()";
//    $query = "SELECT message, actor_id FROM stream WHERE source_id = 100000526102422";
//    $query = "SELECT content,title FROM message WHERE uid = me()";
//$query = "SELECT message_id, body FROM message WHERE thread_id IN (
//            			SELECT thread_id FROM thread WHERE folder_id IN (
//            				SELECT folder_id FROM mailbox_folder WHERE viewer_id = me()
//            			)
//            		)";

    /*
     * Friends' comments on my posts(note, linke, status)
     */
//    $query = "SELECT fromid, text FROM comment 
//    			WHERE fromid != me() 
//    			AND object_id IN (SELECT note_id FROM note WHERE uid = me())
//    			OR object_id IN (SELECT status_id FROM status WHERE uid = me())
//    			OR object_id IN (SELECT link_id FROM link WHERE owner = me())";
    /*
     * My comments on friends' posts(note, linke, status)
     */
//    $query = "SELECT text FROM comment 
//    		WHERE ( 
//            	object_id IN (
//            		SELECT note_id FROM note WHERE uid IN (
//            			SELECT uid2 FROM friend WHERE uid1 = me()
//            		)
//            	)
//            	OR object_id IN (
//            		SELECT status_id FROM status WHERE uid IN (
//            			SELECT uid2 FROM friend WHERE uid1 = me()
//            		)
//            	)
//            	OR object_id IN (
//            		SELECT link_id FROM link WHERE owner IN (
//            			SELECT uid2 FROM friend WHERE uid1 = me()
//            		)
//            	)
//            ) AND fromid = me()";
    /*
     * Friends' comments on my messages
     */
//    $query = "SELECT author_id, body FROM message 
//    		WHERE thread_id IN (
//    			SELECT thread_id FROM thread WHERE folder_id IN (
//    				SELECT folder_id FROM mailbox_folder WHERE viewer_id = me()
//    			)
//    		)
//    		";

    /*
     * my message
     */
//    $query = "select message_id, thread_id, author_id from message where thread_id in (
//            	    select thread_id from thread where folder_id = 1 or folder_id = 0
//                )";
//    $query = "select thread_id, folder_id, subject, recipients, message_count from thread where folder_id = 0 or folder_id = 1";
    
    /*
     * My comments on friends' messages
     */
    
    
    
//    $query = "SELECT uid FROM status WHERE status_id IN (
//                                SELECT object_id FROM comment 
//                                WHERE fromid = me() AND object_id IN (
//                                    SELECT status_id FROM status WHERE uid IN (
//                                        SELECT uid2 FROM friend WHERE uid1 = me()
//                                    )
//                                )
//                            )";
//    
//    $result = $facebook->api(array(
//    	'method' => 'fql.query',
//        'query' => $query
//    ));

    $query = "select uid1, uid2 from friend where uid1 in (select uid2 from friend where uid1 = me()) and uid2 in (select uid2 from friend where uid1 = me())";
    //15720738 
    $result = callFQL($query);
    
    print_r($result);

}catch(FacebookApiException $e){
    print($e);
}
?>